<template>
  <div class="column-list">
    <div v-for="column in columnList" :key="column._id" class="list-item">
      <img :src="column.avatar && column.avatar.fitUrl" :alt="column.title" />
      <h5>{{ column.title }}</h5>
      <p>{{ column.description }}</p>
      <router-link :to="`/column/${column._id}`" class="btn btn-primary link">
        进入专栏
      </router-link>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from "vue";
import type { ColumnProps } from "../store/column";
import { addColumnAvatar } from "../helper";

const props = defineProps<{
  list: ColumnProps[];
}>();

const columnList = computed(() => {
  return props.list.map((column) => {
    addColumnAvatar(column, 50, 50);
    return column;
  });
});
</script>

<style scoped>
.column-list {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;

  .list-item {
    flex: 0 0 425px;
    box-sizing: border-box;
    margin-bottom: 24px;
    padding: 16px;
    border: 1px solid rgba(0, 0, 0, 0.125);
    border-radius: 4px;
    box-shadow: 1px 3px rgba(0, 0, 0, 0.05);

    h5 {
      margin-bottom: 8px;
      font-weight: normal;
      font-size: 20px;
    }

    p {
      line-height: 20px;
      height: 60px;
      -webkit-line-clamp: 3;
      -webkit-box-orient: vertical;
      display: -webkit-box;
      text-overflow: ellipsis;
      overflow: hidden;
      margin-bottom: 16px;
      font-size: 16px;
      color: rgb(108, 117, 125);
    }

    .link {
      background: none;
      border: 1px solid #0d6efd;
      color: #0d6efd;

      &:hover {
        background-color: #0d6efd;
        border-color: #0d6efd;
        color: #fff;
      }
    }
  }
}
</style>
